fix(hooks): improve pattern extraction and structured MEMORY.md entries#185
fix(hooks): improve pattern extraction and structured MEMORY.md entries#185maystudios merged 2 commits intomainfrom
Conversation
Add extractPattern function with prefix matching, bullet extraction, and sentence-based fallback. Change MEMORY.md entry format to pipe-delimited headers (### date | session | reason | commits) with single-line commit lists. Add comprehensive tests for the new extractPattern function. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use template literals instead of string concatenation and optional chaining instead of non-null assertions per biome lint rules. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the maxsim-capture-learnings stop hook to extract a higher-signal “pattern” summary from the assistant’s last message and to write more compact, structured MEMORY.md entries that better fit within line limits.
Changes:
- Added
extractPattern()to detect prefixed “Pattern/Learning/…” lines, summarize short bullet lists, and fall back to last sentence / last characters. - Changed
MEMORY.mdentry formatting to a pipe-delimited### date | session | reason | commitsheader and a single-line commit list. - Hoisted configuration (
PATTERN_PREFIXES) and extracted the 200-char cap intoPATTERN_MAX_LENGTH.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/cli/src/hooks/maxsim-capture-learnings.ts | Introduces extractPattern() and updates appendLearning() output format + pattern extraction integration. |
| packages/cli/tests/unit/capture-learnings.test.ts | Updates appendLearning expectations for the new format and adds unit tests for extractPattern(). |
Comments suppressed due to low confidence (1)
packages/cli/src/hooks/maxsim-capture-learnings.ts:146
extractPattern()can return strings that already include labels/bullets (e.g., "Pattern: ..." or "- Found that ..."). Appending that into- pattern: ${patternSummary}can produce redundant or awkward output like "- pattern: Pattern: ..." or "- pattern: - Found ..." in MEMORY.md. Consider normalizingextractPattern()to return plain text (strip leading bullets and known prefixes) or makeappendLearning()smart enough to avoid double-prefixing when the extracted pattern is already formatted.
if (patternSummary) {
parts.push(`- pattern: ${patternSummary}`);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const parts = [ | ||
| `## Session ${today()}${sessionLabel}${reasonLabel}`, | ||
| `- ${commits.length} commit(s) made this session`, | ||
| commitLines, | ||
| `### ${today()} | ${sessionLabel} | ${reasonLabel} | ${commits.length} commits`, | ||
| commitLine, |
There was a problem hiding this comment.
The new header always uses "${commits.length} commits", which yields grammatically incorrect output for a single commit ("1 commits"). Consider pluralizing ("1 commit" vs "N commits") and aligning the commit line label similarly ("- commit:" vs "- commits:") so MEMORY.md entries read correctly.
|
🎉 This PR is included in version 5.13.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
extractPatternfunction with prefix matching (Pattern:, Learning:, etc.), bullet extraction, and last-sentence fallback for smarter pattern extraction from assistant messages## Sessionwith separate commit lines to compact pipe-delimited### date | session | reason | commitsheaders with single-line commit listsPATTERN_MAX_LENGTHconstant and hoistPATTERN_PREFIXESto module scopeTest plan
🤖 Generated with Claude Code